<template>
  <div>
    <FaPageMain>
      <!--    搜索框-->
      <div style="margin: 10px 0">
        <el-form :inline="true" :model="selectForm" class="demo-form-inline">
          <el-form-item label="用户账号">
            <el-input v-model="selectForm.userAccount" placeholder="请输入用户账号" clearable />
          </el-form-item>
          <el-form-item label="用户名称">
            <el-input v-model="selectForm.userName" placeholder="请输入用户名称" clearable />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="list">查询</el-button>
          </el-form-item>
        </el-form>
      </div>

      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="recordId" label="序号"/>
        <el-table-column prop="userId" label="用户编号"/>
        <el-table-column prop="userAccount" label="用户账号"/>
        <el-table-column prop="userName" label="用户名称"/>
        <el-table-column prop="spotId" label="车位序号"/>
        <el-table-column prop="spotNumber" label="车位编号"/>
        <el-table-column prop="location" label="距离入口">
          <template #default="{ row }">
            {{ row.location ? `${row.location}m` : '—' }}
          </template>
        </el-table-column>
        <el-table-column prop="fee" label="费用"/>
        <el-table-column prop="startTime" label="停车开始时间"/>
        <el-table-column prop="endTime" label="停车结束时间"/>
        <el-table-column prop="createdTime" label="创建时间"/>
        <el-table-column prop="updatedTime" label="更新时间"/>
      </el-table>
      <div class="example-pagination-block">
        <el-pagination
          v-model:current-page="current"
          v-model:page-size="size"
          :page-sizes="[5, 10, 20, 50]"
          :size="size"
          :disabled="disabled"
          :background="background"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </FaPageMain>
  </div>
</template>

<script lang="js">
import api from '@/api'
import {toast} from "vue-sonner";

export default {
  created() {
    this.list()
  },
  data() {
    return {
      tableData: [],
      current: 1,
      size: 5,
      total: 50,
      status: undefined,
      selectForm: {
        userAccount: undefined,
        userName: undefined
      }
    }
  },
  methods: {
    list() {
      const pageParams = {
        current: this.current,
        pageSize: this.size,
        ...this.selectForm
      }
      api.post("/record/list", pageParams).then(res => {
        console.log(res)
        this.tableData = res.data.records
        this.size = res.data.size
        this.current = res.data.current
        this.total = res.data.total
      })
    },
    handleSizeChange(val) {
      this.pageSize = val
      this.list()
    },
    handleCurrentChange(val) {
      this.current = val
      this.list()
    }
  }
}
</script>

<style scoped>
.example-pagination-block {
  margin-top: 10px;
}

.demo-form-inline .el-input {
  --el-input-width: 220px;
}

.demo-form-inline .el-select {
  --el-select-width: 220px;
}
</style>
